package com.pengweiwei.androidzygote.main;

import android.text.TextUtils;

import com.pengweiwei.androidzygote.BuildConfig;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by weiwei on 2015/9/16.
 * <p/>
 * 与服务器通讯的URLs
 * <p/>
 * 基本参数的配置
 */
public class UrlCenter {

// URI == scheme://host:port/path

    public final static String SCHEME;
    public final static String HOST;
    public final static String PORT;
    // http://localhost:8080/QAProject/TestUrlServlet

    static {
        if (BuildConfig.DEBUG || BuildConfig.BUILD_TYPE.equals("alpha") || BuildConfig.BUILD_TYPE.equals("beta")) {
            // 开发环境的url配置
            SCHEME = "http";
            HOST = "192.168.1.109";
            PORT = "8080";
        } else {

            // 正式环境的url配置
            SCHEME = "http";
            HOST = "api.quhepai.com"; //"192.168.3.254";
            PORT = "";
        }
    }


    public final static String AUTHOURITY;
    // URL 前缀
    public final static String URL_PREFIX;

    static {
        if (!TextUtils.isEmpty(PORT)) {
            AUTHOURITY = HOST + ":" + PORT;
        } else {
            AUTHOURITY = HOST;
        }
        URL_PREFIX = SCHEME + "://" + AUTHOURITY;
    }


    // ---------------   All Urls -------------------

    public static final String IMAGE_PREFIX = "http://tpshop.test.com";


    public static final String URL_NORMAL_DATA = URL_PREFIX + "/QAProject/TestUrlServlet";

    public static final String GOODS_LIST = "http://tpshop.test.com/api/goods/lists";

    public static final String GOODS_DETAIL = "http://tpshop.test.com/api/goods/detail";

    public static final String GOODS_COMMENT = "http://tpshop.test.com/api/goods/comments";


    // --------------  All params keys --------------

    public static class Param {
        public static final String IMSI = "imsi";
        public static final String IMEI = "imei";
        public static final String USERID = "user_id";
        public static final String TOKEN = "token";
        public static final String AREAID = "area_id";
        public static final String LONG = "long";
        public static final String LAT = "lat";
        public static final String SERVER_API_VERSION = "ver";
        public static final String CHANNEL_ID = "ch";
        public static final String PAGE = "pageNo";
        public static final String PAGE_SIZE = "pageSize";
    }

    public static final String makeImageUrl(String srcUrl) {
        return IMAGE_PREFIX + srcUrl;
    }

    public static final List<String> makeImageUrl(List<String> srcUrls) {
        List<String> retUrls = new ArrayList<>();
        if (srcUrls != null && srcUrls.size() > 0) {
            for (int i = 0; i < srcUrls.size(); i++) {
                retUrls.add(makeImageUrl(srcUrls.get(i)));
            }
        }
        return retUrls;
    }

}